﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SetSailStart
{
    public partial class Forms : Form
    {
        public Forms()
        {
            InitializeComponent();
            textBox1.Height = 40;
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            RenderHelper.SetFormRoundRectRgn(this, 35);
        }

        /// <summary>
        /// 重写WndProc方法,实现窗体移动和禁止双击最大化
        /// </summary>
        /// <param name="m">Windows 消息</param>
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x4e:
                case 0xd:
                case 0xe:
                case 0x14:
                    base.WndProc(ref m);
                    break;
                case 0x84://鼠标点任意位置后可以拖动窗体
                    this.DefWndProc(ref m);
                    if (m.Result.ToInt32() == 0x01)
                    {
                        m.Result = new IntPtr(0x02);
                    }
                    break;
                case 0xA3://禁止双击最大化
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }

        private void Forms_Load(object sender, EventArgs e)
        {
            string file = System.IO.Path.Combine(Application.StartupPath + "\\start.jpg");
            Image i = new Bitmap(file);
            pictureBox1.Image = GetRound(file);
        }

        //使用Bitmap 绘制圆形
        private Bitmap GetRound(string file)
        {
            using (Image i = new Bitmap(file))
            {
                Bitmap b = new Bitmap(i.Width, i.Height); //初始像素值
                //Bitmap b = new Bitmap(50, 50);
                using (Graphics g = Graphics.FromImage(b))
                {
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //指定抗锯齿
                    using (System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Alternate))
                    {
                        p.AddEllipse(0, 0, i.Width, i.Height);//添加椭圆
                        //p.AddEllipse(0, 0, 50, 50);
                        g.FillPath(new TextureBrush(i), p);//填充内部
                    }
                    //g.FillEllipse(new TextureBrush(i), 0, 0, i.Width, i.Height);
                }
                return b;
            }
        }
    }
}
